package controller

import (
	"bluebell/logic"
	"bluebell/models"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

func CommunityHandler(ctx *gin.Context) {
	data, err := logic.CommunityList()
	if err != nil {
		zap.L().Error("logic.GetCommunityList failed", zap.Error(err))
		ResponseError(ctx, 400, "服务器繁忙") // 不轻易暴露服务端报错
		return
	}
	ResponseSuccess(ctx, 200, "ok", data)
}

func CommunityDetailHandler(ctx *gin.Context) {
	idStr := ctx.Param("id")
	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		ResponseError(ctx, 400, "参数有误")
	}
	var data *models.CommunityDetail
	data, err = logic.CommunityDetail(id)
	if err != nil {
		zap.L().Error("logic.GetCommunityDetail failed", zap.Error(err))
		ResponseError(ctx, 400, "服务器繁忙") // 不轻易暴露服务端报错
		return
	}
	ResponseSuccess(ctx, 200, "ok", data)
}
